from rest_framework import serializers
from django.contrib.auth.models import User


class LoginDeserializers(serializers.Serializer):
    username = serializers.CharField(label='username', max_length=50, required=True, help_text="用户名/邮箱")
    password = serializers.CharField(label='username', max_length=100, required=True, help_text="密码")


class LoginSerializer(serializers.Serializer):
    token = serializers.CharField(label='token', max_length=50, allow_null=False)
    username = serializers.CharField(label='username', max_length=50, allow_null=False)
    email = serializers.CharField(label='username', max_length=50, allow_null=True)
    id = serializers.IntegerField(label='user_id', allow_null=False)


class RegisterDeserializer(serializers.Serializer):
    username = serializers.CharField(label='username', max_length=50, required=True, help_text="用户名")
    email = serializers.CharField(label='email', max_length=50, required=False, allow_null=True, default=None, help_text="邮箱")
    password = serializers.CharField(label='password', max_length=100, required=True, help_text="密码")
    password2 = serializers.CharField(label='password2', max_length=100, required=True, help_text="确认密码")


# 注：这里用的是 serializers.ModelSerializer，而不是serializers.Serializer
class RegisterSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = '__all__'


class LogoutDeserializers(serializers.Serializer):
    user_id = serializers.IntegerField(label='user_id', required=True, allow_null=False)
